{% extends "base.html" %}
{% block content %}
<script>
        // 编辑表单
    function get_edit_info($this)
    {
        var md_AppName = $($this).parent().parent("tr").find("td:eq(1)").html()
        var md_WarFilePath = $($this).parent().parent("tr").find("td:eq(2)").html()
        var md_DeployIp = $($this).parent().parent("tr").find("td:eq(3)").html()
        var md_DeployTmpPath = $($this).parent().parent("tr").find("td:eq(4)").html()
        var md_DeployPath = $($this).parent().parent("tr").find("td:eq(5)").html()
        var md_ContainerPath = $($this).parent().parent("tr").find("td:eq(6)").html()

        if(!$this)
        {
            alert('Error！');
            return false;
        }

    $.ajax(
    {
         success:function ()
            {
                $("#md_AppName").val(md_AppName);
                $("#md_WarFilePath").val(md_WarFilePath);
                $("#md_DeployIp").val(md_DeployIp);
                $("#md_DeployTmpPath").val(md_DeployTmpPath);
                $("#md_DeployPath").val(md_DeployPath);
                $("#md_ContainerPath").val(md_ContainerPath);
            },
         error:function()
            {
                alert('请求出错');
            },
          complete:function()
            {
                // $('#tips').hide();
            }
    });
        return false;
    }
    
    function update_host_info() {
        var AppName = $('#md_AppName').val();
        var WarFilePath = $('#md_WarFilePath').val();
        var DeployIp = $('#md_DeployIp').val();
        var DeployTmpPath = $('#md_DeployTmpPath').val();
        var DeployPath = $('#md_DeployPath').val();
        var ContainerPath = $('#md_ContainerPath').val();
        $.ajax({
            type: "POST",
            url: "/hosts_info/update_app_deploy",
            data:{
                "AppName": AppName,
                "WarFilePath": WarFilePath,
                "DeployIp": DeployIp,
                "DeployTmpPath": DeployTmpPath,
                "DeployPath": DeployPath,
                "ContainerPath": ContainerPath
            },

            success: function(){
                $(function() {
                    $('#updateInfoModal').modal('hide')
                });
                swal({
                    title: "更新成功！",
                    text: "已录入数据库",
                    timer: 500,
                    showConfirmButton: false
                },
                        function () {
                        setTimeout(function(){
                            window.location.reload();
                        }, 500);
                });
            },
            error: function () {
                alert("异常！");
            },
        })
    }


    function add_host_info() {
        var AppName = $('#add_AppName').val();
        var WarFilePath = $('#add_WarFilePath').val();
        var DeployIp = $('#add_DeployIp').val();
        var DeployTmpPath = $('#add_DeployTmpPath').val();
        var DeployPath = $('#add_DeployPath').val();
        var ContainerPath = $('#add_ContainerPath').val();
        $.ajax({
            type: "POST",
            url: "/hosts_info/adddeploy",
            data:{
                "AppName": AppName,
                "WarFilePath": WarFilePath,
                "DeployIp": DeployIp,
                "DeployTmpPath": DeployTmpPath,
                "DeployPath": DeployPath,
                "ContainerPath": ContainerPath,
            },

            success: function(){
                $(function() {
                    $('#addInfoModal').modal('hide')
                });
                swal({
                    title: "新增成功！",
                    text: "已录入数据库",
                    timer: 500,
                    showConfirmButton: false
                },
                        function () {
                        setTimeout(function(){
                            window.location.reload();
                        }, 500);
                });
            },
            error: function () {
                alert("异常！");
            },
        })
    }

    function delete_info($this) {
        var del_ip_add = $($this).parent().parent("tr").find("td:eq(1)").html()
        $.ajax({
            type: "POST",
            url: "/hosts_info/delhost",
            data:{
                "del_ip_add": del_ip_add
            },

            success: function(){
//                swal({
//                    title: "删除成功！",
//                    text: "已从数据库删除",
//                    timer: 500,
//                    showConfirmButton: false
//                },
//                        function () {
//                        setTimeout(function(){
//                            window.location.reload();
//                        }, 500);
//                });
                swal({
                  title: "确定删除该主机？",
                  text: "此操作会删除关于该主机的所有信息！",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "确定！",
                  cancelButtonText: "取消",
                  closeOnConfirm: false
                },
                function(){
                  swal("删除成功", "该主机已从数据库删除！", "success");
                });
            },
            error: function () {
                alert("异常！");
            },
        })
    }


</script>

<HR>
<form class="form-horizontal" role="form" action="" method="post" name="app_add">
    {{ hostsform.hidden_tag() }}
    <div class="row col-xs-12 form-group">
            <div class="col-xs-2  col-xs-offset-8">
                {{ hostsform.ip_address(class="form-control", placeholder="Input IP Address") }}
            </div>
        <div class="col-xs-2">
            <button class="btn btn-info btn-search" style="margin-left:3px">Search</button>
            <button type="button" class="btn btn-primary" data-toggle="modal" value="新增" data-target="#addInfoModal">Add</button>
         </div>
    </div>
</form>

<div class="row">
    <div class="col-md-12 col-md-offset-0">
            <table align="center" class="table table-condensed table-bordered" data-toggle="table">
              <!--<caption>服务器列表信息如下</caption>-->
              <thead>
                <tr class="info">
                    <th>ID</th>
                    <th>AppName</th>
                    <th>WarFilePath</th>
                    <th>DeployIp</th>
                    <th>DeployTmpPath</th>
                    <th>DeployPath</th>
                    <th>ContainerPath</th>
                    <th>Operation</th>
                </tr>
              </thead>
             {% for result in db_result %}
              <tbody>
                <tr>
                    <td>{{result[0]}}</td>
                    <td>{{result[1]}}</td>
                    <td>{{result[2]}}</td>
                    <td>{{result[3]}}</td>
                    <td>{{result[4]}}</td>
                    <td>{{result[5]}}</td>
                    <td>{{result[6]}}</td>
                    <td class="col-md-2">
                        <!--<a href="#" class="btn btn-info btn-sm" disabled="disabled"><span class="glyphicon glyphicon-refresh"></span></a>-->
                        <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" onclick="get_edit_info(this)" data-target="#updateInfoModal"><span class="glyphicon glyphicon-edit"></span></button>
                        <button type="button" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-play"></span></button>
                        <button type="button" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-stop"></span></button>
                        <button type="button" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-repeat"></span></button>
                    </td>
                </tr>
              </tbody>
             {% endfor %}
            </table>
    </div>
                                                                      <!-- 更新信息模态框（Modal） -->
        <form method="post" action="" class="form-horizontal" role="form" id="update_form_data" onsubmit="" style="margin: 20px;">
        <div class="modal fade" id="updateInfoModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="updateModalLabel">
                            应用部署信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label for="md_AppName" class="col-sm-2 control-label">应用名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" disabled="disabled" name="md_AppName" value="{md_AppName}" id="md_AppName">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="md_WarFilePath" class="col-sm-2 control-label">目录文件</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="md_WarFilePath" value="{md_WarFilePath}" id="md_WarFilePath" placeholder="输入mvn生成war文件的路径">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="md_DeployIp" class="col-sm-2 control-label">部 署 I P </label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="md_DeployIp" value="{md_DeployIp}" id="md_DeployIp" placeholder="输入应用部署的服务器IP">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="md_DeployTmpPath" class="col-sm-2 control-label">临时目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="md_DeployTmpPath" value="{md_DeployTmpPath}" id="md_DeployTmpPath" placeholder="输入应用部署的临时目录">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="md_DeployPath" class="col-sm-2 control-label">部署目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="md_DeployPath" value="{md_DeployPath}" id="md_DeployPath" placeholder="输入应用部署的目录">
                                    <!--<textarea  class="form-control"  name="md_DeployPath" value="{md_DeployPath}" id="md_DeployPath" placeholder="input DeployPath"></textarea>-->
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="md_ContainerPath" class="col-sm-2 control-label">容器目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="md_ContainerPath" value="{md_ContainerPath}" id="md_ContainerPath" placeholder="输入应用使用容器的目录">
                                    <!--<textarea  class="form-control"  name="md_DeployPath" value="{md_DeployPath}" id="md_DeployPath" placeholder="input DeployPath"></textarea>-->
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="button" class="btn btn-primary" onclick="update_host_info();">
                            提交
                        </button><span id="tip"> </span>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
        </form>

                                                                      <!-- 新增信息模态框（Modal） -->
        <form method="post" action="" class="form-horizontal" role="form" id="add_form_data" onsubmit="" style="margin: 20px;">
        <div class="modal fade" id="addInfoModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="addModalLabel">
                            录入应用部署信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label for="add_AppName" class="col-sm-2 control-label">应用名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_AppName" value="" id="add_AppName" placeholder="输入应用名称（英文）">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="add_WarFilePath" class="col-sm-2 control-label">目录文件</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_WarFilePath" value="" id="add_WarFilePath" placeholder="输入mvn生成war文件的路径">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="add_DeployIp" class="col-sm-2 control-label">部 署 I P </label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_DeployIp" value="" id="add_DeployIp" placeholder="输入应用部署的服务器IP">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="add_DeployTmpPath" class="col-sm-2 control-label">临时目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_DeployTmpPath" value="" id="add_DeployTmpPath" placeholder="输入应用部署的临时目录">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="add_DeployPath" class="col-sm-2 control-label">部署目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_DeployPath" value="" id="add_DeployPath" placeholder="输入应用部署的目录">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="add_ContainerPath" class="col-sm-2 control-label">容器目录</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="add_ContainerPath" value="" id="add_ContainerPath" placeholder="输入应用使用容器的目录">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="button" class="btn btn-primary" onclick="add_host_info();">
                            提交
                        </button><span id="add_tip"> </span>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
        </form>
</div>

{% endblock %}

